package MyGO.dao.impl;

import MyGO.Form.TrackForm;
import MyGO.dao.ITrackFormDao;
import MyGO.utils.FileUtils.FileIO;
import com.fasterxml.jackson.core.type.TypeReference;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class TrackFormImpl implements ITrackFormDao {
    private static List<TrackForm> TRACKFORM_LIST = new ArrayList<>();

    static {
//        TrackForm trackForm1 = new TrackForm();
//        trackForm1.setStatus_main("未叫号");
//        trackForm1.getPatientInfoForm().setName("李一");
//        trackForm1.getRegistForm().setDoctorID("111");
//        TrackForm trackForm2 = new TrackForm();
//        trackForm2.setStatus_main("未叫号");
//        trackForm2.getPatientInfoForm().setName("张一");
//        trackForm2.getRegistForm().setDoctorID("111");
//        TrackForm trackForm3 = new TrackForm();
//        trackForm3.setStatus_main("未叫号");
//        trackForm3.getPatientInfoForm().setName("王一");
//        trackForm3.getRegistForm().setDoctorID("112");
//        TrackForm trackForm4 = new TrackForm();
//        trackForm4.setStatus_main("未叫号");
//        trackForm4.getPatientInfoForm().setName("李二");
//        trackForm4.getRegistForm().setDoctorID("112");
//        TrackForm trackForm5 =  new TrackForm();
//        trackForm5.setStatus_main("未叫号");
//        trackForm5.getPatientInfoForm().setName("王虎");
//        trackForm5.getRegistForm().setDoctorID("113");
//        TrackForm trackForm6 =  new TrackForm();
//        trackForm6.setStatus_main("未叫号");
//        trackForm6.getPatientInfoForm().setName("刘波");
//        trackForm6.getRegistForm().setDoctorID("113");
////        TrackForm trackForm7 =  new TrackForm();
////        TrackForm trackForm8 =  new TrackForm();
////        TrackForm trackForm9 =  new TrackForm();
////        TrackForm trackForm10 =  new TrackForm();
//        TRACKFORM_LIST.add(trackForm1);
//        TRACKFORM_LIST.add(trackForm2);
//        TRACKFORM_LIST.add(trackForm3);
//        TRACKFORM_LIST.add(trackForm4);
//        TRACKFORM_LIST.add(trackForm5);
//        TRACKFORM_LIST.add(trackForm6);

        TypeReference<List<TrackForm>> typeRef = new TypeReference<List<TrackForm>>() {};
        try {
            TRACKFORM_LIST = FileIO.readObjectFromJsonFile("TrackForm.json", typeRef);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.println(TRACKFORM_LIST);
    }
    @Override
    public List<TrackForm> selectAllTrackForm() {
        return TRACKFORM_LIST;
    }

    @Override
    public List<TrackForm> selectTrackFormById(String ID) {
        return TRACKFORM_LIST.stream().filter(trackForm -> trackForm.getId().contains(ID))
                .collect(Collectors.toList());
    }

    @Override
    public List<TrackForm> selectTrackFormByName(String name) {
        return TRACKFORM_LIST.stream().filter(trackForm -> trackForm.getPatientInfoForm().getName().contains(name))
                .collect(Collectors.toList());
    }

    @Override
    public  List<TrackForm> selectTrackFormByMedicine(String status) {
        return TRACKFORM_LIST.stream().filter(trackForm ->
                trackForm.getStatus_vail().equals(status)).collect(Collectors.toList());
    }

    @Override
    public List<TrackForm> selectTrackFormByStatusAndDoctorID(String status, String doctorID) {
        return TRACKFORM_LIST.stream().filter(trackForm ->
                trackForm.getRegistForm().getDoctorID().equals(doctorID) &&
                trackForm.getStatus_main().equals(status)).collect(Collectors.toList());
    }

    @Override
    public List<TrackForm> selectTrackFormByStatus(String status) {
        return TRACKFORM_LIST.stream().filter(trackForm ->
                trackForm.getStatus_main().equals(status)).collect(Collectors.toList());
    }

    @Override
    public void addTrackForm(TrackForm trackForm){
        TRACKFORM_LIST.add(trackForm);
    }
}
